
package com.akupilih.app;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

import com.akupilih.app.adapter.CustomAdapter;
import com.akupilih.app.entity.E_Penghargaan;
import com.akupilih.app.model.DBClass;
import com.akupilih.app.model.Utils;

public class PenghargaanFragment extends Fragment {

    private FragmentActivity myContext;
    ListView listView;
    List<E_Penghargaan> dataList;
    ArrayList<HashMap<String, Object>> postitem;
    public static final String KEY_HEAD = "title";
    public static final String KEY_BODY = "jabatan";
    public static final String KEY_FOOT = "tahun";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View rootView = inflater.inflate(R.layout.fragment_pasangan, container,
                false);
        listView = (ListView) rootView.findViewById(R.id.listview);
        DBClass db = new DBClass(getActivity());
        String id = getArguments().getString("id");
        Utils.TRACE("PenghargaanFragment", "onCreateView id yang di query : " + id);
        dataList = db.selectPenghargaan(id);
        setList(dataList);
        return rootView;
    }

    private void setList(List<E_Penghargaan> dataList2) {
        postitem = new ArrayList<HashMap<String, Object>>();
        if (dataList2 != null) {
            for (E_Penghargaan e : dataList2) {
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put(KEY_HEAD, e.getRingkasan());
                map.put(KEY_BODY, e.getInstitusi());
                map.put(KEY_FOOT, e.getTgl());
                postitem.add(map);
            }
            ListAdapter adapter = new CustomAdapter(myContext, postitem,
                    R.layout.row_organisasi, new String[] {
                            KEY_HEAD, KEY_BODY,
                            KEY_FOOT
                    }, new int[] {
                            R.id.head, R.id.body,
                            R.id.foot
                    });
            listView.setAdapter(adapter);
            listView.setDivider(null);

        }

    }

    @Override
    public void onAttach(Activity activity) {
        // TODO Auto-generated method stub
        super.onAttach(activity);
        myContext = (FragmentActivity) activity;

    }

}
